string= input()
list1=string.split()
dict1={}

list1.sort()
# string2=" ".join(list1)
for i in range(len(list1)):
    if dict1.get(list1[i]) is None:
        dict1[list1[i]] =0

    dict1[list1[i]]+=1
list1.sort(key = lambda x:(-dict1[x],len(x),x))
string3=" ".join(list1)
print(string3)